package com.softer.chengxin.param.dao.provider;

import com.softer.chengxin.param.entity.ParamVO;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

/**
 * @author Gong Zhiyang
 * @date 2019/12/13
 */

public class ParamDaoProvider {
    /**
     * 查询参数列表
     * @param map 查询实体
     * @return SQL语句
     */
    public String getList(Map<String, ParamVO> map) {
        StringBuilder sql = new StringBuilder(10);
        ParamVO paramVO = map.get("p");
        sql.append("SELECT id, param_value as paramValue,param_key as paramKey,param_name as paramName,unit,remark,gmt_modify as gmtModify");
        sql.append(" FROM param where 1=1");
        if (StringUtils.isNotBlank(paramVO.getParamName())){
            sql.append(" and INSTR(`param_name`,#{p.paramName})>0 ");
        }
        if (StringUtils.isNotBlank(paramVO.getParamKey())){
            sql.append(" and INSTR(`param_key`,#{p.paramKey})>0 ");
        }
        return sql.toString();
    }
}
